import torch


def apply_random_offset(
    positions: torch.Tensor, *,
    period: float,
) -> torch.Tensor:
    """
    :param positions: shape=[..., seq_len]
    :param period: shape=[]
    :returns: positions: shape=[..., seq_len]
    """

    offset = torch.rand(positions.shape[:-1], dtype=positions.dtype, device=positions.device)
    offset = offset * period
    # [...]

    positions = positions + offset.unsqueeze(-1)
    # [..., seq_len]

    return positions
